package agendaSystem;

/**
 * A class for the creation of meetings based on the day, description, number of agendas and number of slots.
 * 
 * @invar	The description of each meeting must be a valid description for a meeting. 
 * 			| isValidDecription(getDescription())
 * @invar	The day of each meeting must be a valid day for a meeting.
 * 			| isValidDay(getDay())
 * @invar	The slot must be a valid slot for a meeting.
 * 			| isValidSlot(getSlots()) 
 * 
 * @author	Sabrina Knapen, Axel Vranken
 * @version 1.0 
 * 
 */
public class Meeting extends SlottedEntry {
	
	/**
     * Initialize this new meeting with a given description, day, number of slots and number of agendas.
     * 
     * @param	description
	 * 			The description of the new entry.
	 * @param	day
	 * 			The day of the new entry.
	 * @param	agendas
	 * 			The agendas that shall contain the new entry.
	 * @param 	slots
	 * 			The number of slots occupied by the entry.
	 * @pre		The description must be valid for the new entry. 
	 * 			| isValidDescription(description)
	 * @pre		The given day must be a valid day for the entry. 
	 * 			| isValidDay(day)
	 * @pre		The given slots must be valid.
	 * 			| for each slot in slots
	 * 			| 	isValidSlot(slot)
	 * @pre		The given agendas must exist.
	 * 			| for each ag in agendas
	 * 			|		 ag.isTerminated = false
	 * @post	The description of this new meeting is equal to the given
	 * 			description. 
	 * 			| new.getDescription() == description
	 * @post	The day of this new meeting is equal to the given day. 
	 * 			| new.getDay() == day
	 * @post	The agenda of this new meeting is the same as the
	 *          given agenda.
	 *       	| new.getAgenda() == agenda
	 * @post	The given agendas have this new meeting as one of the
	 *         	entries on the given day.
	 *         	| for each ag in agendas
	 *       	| 		ag.getEntriesAt(day).contains(this)
	 * @post    The number of entries for the given agendas on the given day is
	 *          incremented by 1.
	 *          | for each ag in agendas
	 *       	| 		ag.getAllEntries() == ag.getAllEntries() + 1
	 * @effect	The meeting belongs to an array of agendas.
	 * 			| for each ag in agendas
	 * 			| 		ag.addEntry(this)
	 * @effect	The agendas are added to the list of agendas for this entry.
	 * 			| for each ag in agenda
	 * 			| 		this.addAgenda(ag)
	 * @effect	The slots of this new meeting will be added to the list of slots. 
	 * 			| for each slot in slots
	 * 			| 		addSlot(slots)
	 * @throws	IllegalArgumentException	
	 * 		  	There must be at least two agendas to put the meeting in.
	 * 		  	| (agendas.length>=2)	
     */
	public Meeting(Agenda[] agendas, String description, int day, int... slots) throws IllegalArgumentException{
		super(agendas,description, day,slots);
		if(agendas.length<2)
			throw new IllegalArgumentException("Minimum 2 agendas must be given.");
		}			

	/**
	 * Checks whether the given slot is a valid slot for a meeting.
	 * 
	 * @param	slot
	 * 			The slot that needs to be checked.
	 * @return	True if and only if the given slot is not smaller than 1 and not bigger than the maximum number of slots.
	 * 			| result != (slot < 1) && (slot > getMaxSlot())
	 * @return 	True if and only if there are no slots for this meeting yet.
	 * 			| result == (this.getNbSlots == 0)
	 * @return	True if and only if the slots are successive.
	 * 			| result == (this.getFirstSlot() - 1 == slot || this.getLastSlot() + 1 == slot)
	 */
	@Override
	public boolean isValidSlot(int slot){
		if(!super.isValidSlot(slot))
			return false;
		if (this.getNbSlots() == 0)
			return true;
		return(this.getFirstSlot() - 1 == slot || this.getLastSlot() + 1 == slot);	
	}
	
}
